Unit iadearam;

Interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, wwdbdatetimepicker, Grids, Wwdbigrd, Wwdbgrid,
  ExtCtrls, Db, ADODB;

Type
  Tiadearama = Class(TForm)
    Bevel2: TBevel;
    Edit1: TEdit;
    Edit2: TEdit;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Edit3: TwwDBDateTimePicker;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    DBGrid1: TwwDBGrid;
    Label19: TLabel;
    kargonok: TEdit;
    Procedure BitBtn2Click(Sender: TObject);
    Procedure BitBtn1Click(Sender: TObject);
    Procedure FormKeyPress(Sender: TObject; Var Key: Char);
    Procedure FormCreate(Sender: TObject);
    Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
    Procedure Edit1Enter(Sender: TObject);
    Procedure Edit1Exit(Sender: TObject);
    Procedure Edit1KeyDown(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
    Procedure bul(Sender: TObject; Var Key: Char);
    Procedure Edit2Enter(Sender: TObject);
    Procedure Edit2Exit(Sender: TObject);
    Procedure Edit2KeyDown(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
    Procedure Edit3Enter(Sender: TObject);
    Procedure Edit3Exit(Sender: TObject);
    Procedure Edit3KeyDown(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
    Procedure Edit1KeyPress(Sender: TObject; Var Key: Char);
    Procedure DBGrid1DblClick(Sender: TObject);
    Procedure FormActivate(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;

Var
  iadearama: Tiadearama;
  str1, str2, str3, str4: String[40];

Implementation

Uses udmTeknik, uruniade;

{$R *.DFM}

Procedure Tiadearama.BitBtn2Click(Sender: TObject);
Begin
  modalresult := mrok;
End;

Procedure Tiadearama.BitBtn1Click(Sender: TObject);
Begin
  modalresult := mrcancel;
End;

Procedure Tiadearama.FormKeyPress(Sender: TObject; Var Key: Char);
Begin
  If key = #10 Then
  Begin
    key := #0;
    bitbtn2.Click;
  End;
  If key = #27 Then
  Begin
    key := #0;
    modalresult := mrcancel;
  End;

End;

Procedure Tiadearama.FormCreate(Sender: TObject);
Begin
  keypreview := true;
  str1 := '';
  str2 := '';
  str3 := '';
  If Not furuniade.arama.Active Then
  Begin
    furuniade.arama.Close;
    furuniade.arama.SQL.Clear;
    furuniade.arama.SQL.Add(' select distinct i.id,i.firmaadi,i.tarih,h.serino,h.stokkodu,h.cinsi ,h.miktar from iade i,iadestok h');
    furuniade.arama.SQL.Add('where (i.id=h.iadekod) and (i.id=0)');
    furuniade.arama.open;

  End;
End;

Procedure Tiadearama.FormClose(Sender: TObject; Var Action: TCloseAction);
Begin
  action := cafree;
  iadearama := Nil;
End;

Procedure Tiadearama.Edit1Enter(Sender: TObject);
Begin
  edit1.Color := clwhite;
  edit2.Color := clbtnface;
  edit3.Color := clbtnface;
  Edit3.ShowButton := false;
  edit1.text := str1;
  edit2.text := '';
  edit3.text := '';
  edit1.SelectAll;
  edit1.SelText := str1;
  RadioButton1.Checked := true;
End;

Procedure Tiadearama.Edit1Exit(Sender: TObject);
Begin
  str1 := edit1.text;
End;

Procedure Tiadearama.Edit1KeyDown(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Begin
  If key = vk_down Then
  Begin
    edit2.SetFocus;
  End;

End;

Procedure Tiadearama.bul(Sender: TObject; Var Key: Char);
Var
  t: byte;

Begin
  t := TCustomEdit(sender).Tag;
  If key = #13 Then
  Begin
    key := #0;
    furuniade.arama.Close;
    furuniade.arama.SQL.Clear;
    furuniade.arama.SQL.Add(' select distinct i.id,i.firmaadi,i.tarih,h.serino,h.stokkodu,h.cinsi ,h.miktar  from iade i,iadestok h');
    furuniade.arama.SQL.Add('where (i.id=h.iadekod)');
    Case t Of
      2: furuniade.arama.SQL.Add('and (i.id=' + TEdit(sender).text + ')');
      3:
        Begin
          furuniade.arama.SQL.Add('and (i.tarih>:tarih1) and (i.tarih<:tarih2)');
          furuniade.arama.Parameters.ParamByName('tarih1').datatype := ftDate;
          furuniade.arama.Parameters.ParamByName('tarih2').datatype := ftDate;
          furuniade.arama.Parameters.ParamByName('tarih1').value := edit3.Date - 1;
          furuniade.arama.Parameters.ParamByName('tarih2').value := edit3.Date + 1;
        End;
      4: furuniade.arama.SQL.Add('and (i.kargotno=' + #39 + TEdit(sender).text + #39 + ')');

    End;
    furuniade.arama.SQL.Add('order by i.id');
    furuniade.arama.open;
    If furuniade.arama.RecordCount > 0 Then
      If t = 2 Then
        modalresult := mrok
      Else
        dbgrid1.setfocus;
  End;
End;

Procedure Tiadearama.Edit2Enter(Sender: TObject);
Begin
  edit2.Color := clwhite;
  edit1.Color := clbtnface;
  edit3.Color := clbtnface;
  Edit3.ShowButton := false;
  edit2.text := str2;
  edit1.text := '';
  edit3.text := '';
  edit2.SelectAll;
  edit2.SelText := str2;
  RadioButton2.Checked := true;
End;

Procedure Tiadearama.Edit2Exit(Sender: TObject);
Begin
  str2 := edit2.text;
End;

Procedure Tiadearama.Edit2KeyDown(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Begin

  If key = vk_down Then
  Begin
    edit3.SetFocus;
  End;

  If key = vk_up Then
  Begin
    edit1.SetFocus;
  End;

End;

Procedure Tiadearama.Edit3Enter(Sender: TObject);
Begin
  edit3.Color := clwhite;
  edit1.Color := clbtnface;
  edit2.Color := clbtnface;
  edit3.text := str3;
  Edit3.ShowButton := True;
  edit1.text := '';
  edit2.text := '';
  edit3.SelectAll;
  edit3.SelText := str3;
  RadioButton3.Checked := true;

End;

Procedure Tiadearama.Edit3Exit(Sender: TObject);
Begin
  str3 := edit3.text;
End;

Procedure Tiadearama.Edit3KeyDown(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Begin
  If key = vk_up Then
  Begin
    edit2.SetFocus;
  End;

End;

Procedure Tiadearama.Edit1KeyPress(Sender: TObject; Var Key: Char);
Begin
  If key = #13 Then
  Begin
    furuniade.arama.Close;
    furuniade.arama.SQL.Clear;
    furuniade.arama.SQL.Add(' select * from iade i, iadestok h');
    furuniade.arama.SQL.Add('where (i.id=h.iadekod)');
    furuniade.arama.SQL.Add('and (h.serino=''' + TEdit(sender).text + ''')');
    furuniade.arama.SQL.Add('order by i.id');
    furuniade.arama.open;
  End;
End;

Procedure Tiadearama.DBGrid1DblClick(Sender: TObject);
Begin
  modalresult := mrok;
End;

Procedure Tiadearama.FormActivate(Sender: TObject);
Begin
  iadearama.Edit2.SetFocus;
End;

End.
